
using System;

namespace AtDevice
{
    public class AtUtils
    {   
        /// <summary>
        /// Convert the network enum value to human-readable form.
        /// </summary>
        public static string GetNetworkName(NetworkEnum network)
        {
            switch (network)
            {
                case NetworkEnum.GprsNetwork:
                    return "GPRS";
                case NetworkEnum.HsdpaNetwork:
                    return "HSDPA";
                case NetworkEnum.HspaNetwork:
                    return "HSPA";
                case NetworkEnum.HsupaNetwork:
                    return "HSUPA";
                case NetworkEnum.EdgeNetowrk:
                    return "EDGE";
                case NetworkEnum.UmtsNetwork:
                    return "UMTS";
                case NetworkEnum.WcdmaNetwork:
                    return "WCDMA";
                default:
                    return "Unknown";
            }
        }
        
        /// <summary>
        /// Convert the signal (from 0 to 1) value to number of bars (from 0 to 5) to display in user interface.
        /// </summary>
        public static int GetSignalNumberOfBars(double signal)
        {
            const double VERY_LOW_SIGNAL = 0.26;
            const double LOW_SIGNAL = 0.44;
            const double AVERAGE_SIGNAL = 0.64;
            const double GOOD_SIGNAL = 0.84;
            const double EXCELLENT_SIGNAL = 1.0;
            
            if(signal < VERY_LOW_SIGNAL)
                return 1;
            else if(signal < LOW_SIGNAL)
                return 2;
            else if(signal < AVERAGE_SIGNAL)
                return 3;
            else if(signal < GOOD_SIGNAL)
                return 4;
            else if(signal <= EXCELLENT_SIGNAL)
                return 5;
            else
                return 0;
        }
    }
}
